<?php

/**
 * This is the model class for table "comments".
 *
 * The followings are the available columns in table 'comments':
 * @property integer $comm_id
 * @property integer $comm_user
 * @property integer $comm_item
 * @property string $comm_content
 * @property string $comm_time
 *
 * The followings are the available model relations:
 * @property Item $commItem0
 * @property User $commUser0
 */
class Comments extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Comments the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'comments';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('comm_content, comm_time', 'required'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('comm_id, comm_user, comm_item, comm_content, comm_time', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'commItem0' => array(self::BELONGS_TO, 'Item', 'comm_item'),
			'commUser0' => array(self::BELONGS_TO, 'User', 'comm_user'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'comm_id' => 'Comm',
			'comm_user' => 'Comm User',
			'comm_item' => 'Comm Item',
			'comm_content' => 'Comm Content',
			'comm_time' => 'Comm Time',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('comm_id',$this->comm_id);
		$criteria->compare('comm_user',$this->comm_user);
		$criteria->compare('comm_item',$this->comm_item);
		$criteria->compare('comm_content',$this->comm_content,true);
		$criteria->compare('comm_time',$this->comm_time,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}